package com.chixing.controller;

import com.chixing.pojo.Comment;
import com.chixing.pojo.Customer;
import com.chixing.service.ReviewService;
import com.chixing.util.ServerResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class ReviewController {
    @Autowired
    private ReviewService reviewService;
    @PostMapping("/review")
    public ServerResult saveReview(Integer productId, String reviewText, HttpSession session){
        Customer customer=(Customer) session.getAttribute("loginCustroller");
        Integer customerId=customer.getCustumerId();
        System.out.println("customerId:"+customerId);
        Comment comment=new Comment();
        comment.setCommentId(709);
        comment.setCommentStatus(0);
        comment.setCustomerId(customerId);
        comment.setProductId(productId);
        comment.setCommentContent(reviewText);
        comment.setCommentTime(new Date());
        ServerResult result=reviewService.save(comment);
        return result;
    }





}
